import { http, httpGet, httpPost } from '@/utils/http'
import dayjs from 'dayjs'
import getApiUrl from '@/utils/getApiUrl'
import { Tournament } from '@/championship'
import { TournamentStatusEnum } from '@/common/enum'

export const getTournamentList = async (
  param: IPageReqData<{ name?: string; status: TournamentStatusEnum }>,
): Promise<IPageResData<Tournament>> => {
  // http.get<Tournament[]>('/tournament');
  const res = await httpGet<IPageResData<Tournament>>('/tournament/search', param)
  return res.data
}

export const getMyTournamentList = async (): Promise<IPageResData<Tournament>> => {
  const res = await httpGet<Tournament[]>('/tournament/mylist')
  return {
    records: res.data,
    current: 1,
    size: 10,
    total: 10,
  }
}

export const getTournamentDetail = async (id: number): Promise<IResData<Tournament>> => {
  const res = await httpGet<Tournament>(`/tournament/${id}`)
  return res
}

export const getTournamentInfo = (id: number): Promise<IResData<Tournament>> => {
  return Promise.resolve({
    code: 200,
    type: 'success',
    msg: '请求成功',
    data: {
      id,
      name: '成都羽毛球公开赛A',
      type: '羽毛球',
      status: '待审核',
      fromDate: dayjs('2024-09-01 08:00:00').toDate(),
      endDate: dayjs('2024-10-01 18:00:00').toDate(),
      registrationFromDate: dayjs('2024-08-01 08:00:00').toDate(),
      registrationEndDate: dayjs('2025-08-31 18:00:00').toDate(),
      adImage: 'https://dummyimage.com/400x200/3c9cff/fff',
      address: '成都市体育馆',
      concatUserList: [
        { id: 1, name: '张三', phone: '13888888888' },
        { id: 2, name: '李四', phone: '13666666666' },
      ],
      categoryList: [],
      description:
        '成都羽毛球公开赛A是成都市羽毛球协会主办的一项羽毛球赛事，比赛地点在成都市体育馆。',
    },
  })
}

type BizContentType = {
  eventType: { [key: string]: { name: string; value: string | number } }
  tournamentType: { [key: string]: { name: string; value: string | number } }
}
export const getBizConstant = async (): Promise<IResData<BizContentType>> => {
  const res = await httpGet<BizContentType>('/biz-constant')
  return res
}
export const saveTournament = async (data: Tournament): Promise<IResData<Tournament>> => {
  const res = await httpPost<Tournament>('/tournament/add', data)
  return res
}
